package nus.mtech.bill;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import nus.mtech.constant.Constant;

public class TextBillPrinter {
	
	public static String getBillStatement(Bill bill){
		return getBillStatement(new SimpleTextBillFormatter(), bill);
	}
	
	public static void printBill(Bill bill, String fileName) throws IOException{
		String billStatement = getBillStatement(bill);
		printToFile(billStatement, fileName);
	}


	public static void printBill(BillFormatter formatter, Bill bill, String fileName) throws IOException{
		String billStatement = getBillStatement(formatter, bill);
		printToFile(billStatement, fileName);
		
	}
	public static String getBillStatement(BillFormatter formatter, Bill bill){
		return (String)formatter.format(bill);
	}
	private static void printToFile(String billStatement, String fileName) throws IOException {
		FileWriter fw = new FileWriter(fileName);
		fw.write(billStatement);
		fw.flush();
		fw.close();
	}
	
	public static void main (String args[]){
		Bill bill = new Bill();
		bill.setAccountNo("Acc1234567");
		bill.setAdditionalCableTVChannelsCharges(20);
		bill.setBillDate(new Date());
		bill.setBillNo("1234");
		bill.setCableTVAdditionalChannelNumber(4);
		bill.setCableTVAddtionalChargePerLine(5);
		bill.setCableTVSubscriptionChargesSummary(30);
		bill.setCustomerAddress("add1;add2;add3;add4");
		bill.setDetailDigitalVoiceSubCallTransfer(11);
		bill.setDetailDigitalVoiceSubChargeLine(6);
		bill.setDetailDigitalVoiceUsageChargeIDDCalls(100);
		bill.setDetailDigitalVoiceUsageChargeLocalCalls(101);
		bill.setDetailMobileVoiceUsageChargeRoamingCalls(102);
		bill.setDetailMobileVoiceChargeSubMobile(8);
		bill.setDetailMobileVoiceChargeSubRoaming(9);
		bill.setDetailMobileVoiceUsageChargeIDDCalls(122);
		bill.setDetailMobileVoiceUsageChargeLocalCalls(33);
		bill.setDetailMobileVoiceUsageChargeRoamingCalls(212);
		bill.setDigitalVoiceNumber("7654321");
		bill.setDigitalVoiceSubscriptionChargesSummary(233);
		bill.setDigitalVoiceUsageChargesSummary(243);
		bill.setDueDate(new Date());
		bill.setMobileVoiceNumber("22222222");
		bill.setMobileVoiceSubscriptionChargesSummary(333);
		bill.setMobileVoiceUsageCharges(2345);
		bill.setPrinted(false);
		bill.setTotalBill(2345);
		bill.setTotalGST(2345*0.07);
	
		try {
			printBill(bill, Constant.BILL_DIR + File.separator + "testBill.txt");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
